/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oim.fx.ui.list;

import javafx.beans.Observable;
import javafx.geometry.Insets;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;

/**
 *
 * @author XiaHui
 */
public class HeadImagePanel extends BorderPane {

//    private final DropShadow dropShadow = new DropShadow();
    private final StackPane rootPane = new StackPane();
    private final StackPane imagePane = new StackPane();
    private final ImageView imageView = new ImageView();
    private final Rectangle clip = new Rectangle();

    public HeadImagePanel() {
        initComponent();
        iniEvent();
    }

    private void initComponent() {
        this.getStyleClass().add("head-common-image-pane");
        this.setCenter(rootPane);
        // this.getChildren().add(headImageShowPane);

        rootPane.getChildren().add(imagePane);
        rootPane.setPadding(new Insets(5, 5, 5, 5));
        
        clip.setArcHeight(8);
        clip.setArcWidth(8);

        imagePane.getChildren().add(imageView);

        imagePane.setClip(clip);
        imagePane.widthProperty().addListener((Observable observable) -> {
            clip.setWidth(imagePane.getWidth());
        });
        imagePane.heightProperty().addListener((Observable observable) -> {
            clip.setHeight(imagePane.getHeight());
        });
    }

    private void iniEvent() {
//        this.setOnMouseEntered((Event event) -> {
//            HeadImagePanel.this.setEffect(dropShadow);
//        });
//        this.setOnMouseExited((Event event) -> {
//            HeadImagePanel.this.setEffect(null);
//        });
    }

    public void setImage(Image image) {
        imageView.setImage(image);
    }
    
    /**
	 * 设置头像大小
	 * 
	 * @author: XiaHui
	 * @param value
	 * @createDate: 2017年5月25日 下午5:59:25
	 * @update: XiaHui
	 * @updateDate: 2017年5月25日 下午5:59:25
	 */
	public void setHeadSize(double value) {
		imageView.setFitHeight(value);
		imageView.setFitWidth(value);

		clip.setArcHeight(value);
		clip.setArcWidth(value);

		clip.setWidth(value);
		clip.setHeight(value);
	}

//    private void initTest() {
//        Image image = ImageBox.getImagePath("Resources/Images/Head/User/1_100.gif", 60, 60);
//        setImage(image);
//    }
}
